package com;

import javafx.application.Application;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/check")
public class Check extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求乱码
        req.setCharacterEncoding("utf-8");
        //设置响应乱码
        resp.setContentType("text/html;charset=utf-8");
        //假定有一个用户的账号密码为 张三/123456

        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println(username+"////"+password);
        HttpSession session = req.getSession();
        ServletContext servletContext = req.getServletContext();
        //在线人数变量
        int alluser = 0;




        if (username.equals("张三") && password.equals("123456") ){
            System.out.println("验证通过");
            session.setAttribute("user1","on");
            alluser++;
            servletContext.setAttribute("online",alluser);
            req.getRequestDispatcher("/Welcome").forward(req,resp);

        }else {
            System.out.println("用户名或密码错误");
            resp.getWriter().write("用户名或密码错误！！！");
        }


    }
}
